package cn.wolfcode.web.page;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;
@Getter@Setter@ToString
public class PageResult {
    private int currentPage = 1;
    private int pageSize = 5;

    private int rows;
    private List<?> result;
    private int totalPage;
    private int prevPage;
    private int nextPage;

    public PageResult(int currentPage,int  pageSize,int  rows,List<?>  result) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.rows = rows;
        this.result = result;
        if (rows < pageSize) {//如果总数据条数小于每页数据条数,上页,下页,总页数都是1,不用执行后面的程序了
            this.prevPage = 1;
            this.nextPage = 1;
            this.totalPage = 1;
            return;
        }

        this.totalPage = rows % pageSize == 0 ? rows / pageSize : rows / pageSize + 1;
        this.prevPage = currentPage - 1 >= 1 ? currentPage - 1 : 1;//当前页-1大于等于1
        this.nextPage = currentPage + 1 <= this.totalPage ? currentPage + 1 : this.totalPage;//当前页+1小于等于总页数

    }

}
